<template>
  <div class="edit-password-page">
    <el-card shadow="hover" :bordered="true">
      <template #header>
        <div class="card-header">
          <el-icon><Key /></el-icon>
          <span>修改密码</span>
        </div>
      </template>
      <el-form :model="form" label-width="120px">
        <el-form-item label="原密码">
          <el-input 
            v-model="form.oldPassword" 
            type="password" 
            placeholder="请输入原密码"
          />
        </el-form-item>
        <el-form-item label="新密码">
          <el-input 
            v-model="form.newPassword" 
            type="password" 
            placeholder="请输入新密码"
          />
        </el-form-item>
        <el-form-item label="确认密码">
          <el-input 
            v-model="form.confirmPassword" 
            type="password" 
            placeholder="请再次输入新密码"
          />
        </el-form-item>
        <el-form-item>
          <el-button 
            type="primary" 
            @click="handleSubmit"
          >
            确认修改
          </el-button>
          <el-button 
            @click="handleReset"
            style="margin-left: 10px;"
          >
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script setup>
import { reactive } from 'vue'
import { ElMessage } from 'element-plus'
import { Key } from '@element-plus/icons-vue'

// 表单数据
const form = reactive({
  oldPassword: '',
  newPassword: '',
  confirmPassword: ''
})

// 提交修改
const handleSubmit = () => {
  if (!form.oldPassword) {
    ElMessage.warning('请输入原密码')
    return
  }
  if (form.newPassword !== form.confirmPassword) {
    ElMessage.warning('两次输入的新密码不一致')
    return
  }
  // 这里可对接实际接口，示例仅做模拟
  ElMessage.success('密码修改成功！')
  // 可在此处调用接口：api/user/editPassword(form)
}

// 重置表单
const handleReset = () => {
  form.oldPassword = ''
  form.newPassword = ''
  form.confirmPassword = ''
}
</script>

<style scoped>
.edit-password-page {
  padding: 20px;
}
.card-header {
  display: flex;
  align-items: center;
}
.card-header .el-icon {
  margin-right: 5px;
}
</style>